#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 状态枚举
typedef enum {
    STATE_IDLE = 0,
    STATE_INIT,
    STATE_RUNNING,
    STATE_PAUSE,
    STATE_ERROR,
    STATE_EXIT,
    STATE_MAX
} state_t;

// 事件枚举
typedef enum {
    EVENT_START = 0,
    EVENT_STOP,
    EVENT_PAUSE,
    EVENT_RESUME,
    EVENT_ERROR,
    EVENT_RESET,
    EVENT_EXIT,
    EVENT_MAX
} event_t;

// 状态机结构体
typedef struct {
    state_t current_state;
    state_t previous_state;
    int initialized;
} state_machine_t;

// 状态处理函数指针类型
typedef state_t (*state_handler_t)(state_machine_t *sm, event_t event);

// 状态转换表结构体
typedef struct {
    state_t current_state;
    event_t event;
    state_t next_state;
    state_handler_t handler;
} state_transition_t;

// 函数声明
int state_machine_init(state_machine_t *sm);
int state_machine_process_event(state_machine_t *sm, event_t event);
const char* state_to_string(state_t state);
const char* event_to_string(event_t event);

// 状态处理函数声明
state_t handle_idle_state(state_machine_t *sm, event_t event);
state_t handle_init_state(state_machine_t *sm, event_t event);
state_t handle_running_state(state_machine_t *sm, event_t event);
state_t handle_pause_state(state_machine_t *sm, event_t event);
state_t handle_error_state(state_machine_t *sm, event_t event);
state_t handle_exit_state(state_machine_t *sm, event_t event);

#endif // STATE_MACHINE_H